<template>
	<view class="content b-t">
		<view class="point-history">
			<view class="list b-b" v-for="(item, index) in newProductList" :key="index">
				<view class="left">
					<view class="tran-type">
						{{item.changeType |formatStatus}}
					</view>
					<view class="tran-time">
						{{item.createTime |formatCreateTime}}
					</view>
				</view>
				<view class="right">
					<view :class="item.changeType==1?'point-minus':'point-plus'" >
						{{item.changeCount}}
					</view>
                    <view class="balance">
						{{item.operateNote}}
					</view>

				</view>
			</view>
		</view>
		

		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
import Api from '@/common/api';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	import { formatDate } from '@/common/date';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
    	components: {

        			uniLoadMore,

        		},
    		data(){
    			return{
    				pageNum: 1,
                            				loadingType: 'more', //加载更多状态
    			integrals:0,
    				newProductList: [],


    			}
    		},
    			//加载更多
                    	onReachBottom() {
                    		this.pageNum = this.pageNum + 1;
                    		this.getNewProductList();
                    	},
                	onPullDownRefresh() {
                	this.pageNum = this.pageNum + 1;
                	this.getNewProductList('refresh');


                		setTimeout(function () {
                			uni.stopPullDownRefresh();
                		}, 2000);
                	},
  filters: {
        formatCreateTime(time) {
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        },

        formatStatus(value) {
          if (value === 1) {
            return '增加';
          } if (value === 2) {
                        return '减少';
                      }

        },
      },
    		async onShow() {
    		this.getNewProductList('refresh');
    		 let params = { };


                                         				let data1 = await Api.apiCall('get', Api.member.currentMember, params);
                             					this.integrals = data1.integration;
    		},
    		onPullDownRefresh() {

    		},
    		methods:{
    		/**
            		 * 统一跳转接口,拦截未登录路由
            		 * navigator标签现在默认没有转场动画，所以用view
            		 */
            		navTo(url) {
            			let token = uni.getStorageSync('token') || '';
            			if (!token) {
            				url = '/pages/public/login';
            			}
            			uni.navigateTo({
            				url: url
            			});
            		},
    		/**
                		     * 获取新品上市信息
                		     */
                		    async getNewProductList(type = 'add', loading){
                		    //没有更多直接返回
                            			if (type === 'add') {
                            				if (this.loadingType === 'nomore') {
                            					return;
                            				}
                            				this.loadingType = 'loading';
                            			} else {
                            				this.loadingType = 'more';
                            			}
                		   //   let params = { pageNum: this.pageNum,orderType:5};
                		      let params = { pageNum: this.pageNum};
                		      let list = await Api.apiCall('get', Api.member.integrationlist, params);


                		        let goodsList = list.records;

                                			if (type === 'refresh') {
                                				this.newProductList = [];
                                			}

                    	this.newProductList = this.newProductList.concat(goodsList);

                                			//判断是否还有下一页，有是more  没有是nomore(测试数据判断大于20就没有了)
                                			this.loadingType = this.newProductList.length > list.total ? 'nomore' : 'more';
                                			if (type === 'refresh') {
                                				if (loading == 1) {
                                					uni.hideLoading();
                                				} else {
                                					uni.stopPullDownRefresh();
                                				}
                                			}

                		    },
    			toGoods(item){
    			console.log(item)
                			let id = item.id;
                            			uni.navigateTo({
                            				url: `../../pagesA/product/giftProduct?id=${id}`
                            			});
                		}
    		}
    	}
    </script>

<style lang='scss'>
	page {
		padding-bottom: 120upx;
		background: #f8f8f8;
	}

	.content {
		position: relative;
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20upx 30upx;
		;
		background: #fff;
		position: relative;
		.amount{
			color: $base-color
		}
		.apply{
			color: #fff;
			border-radius: 10px;
			background: linear-gradient(left, #f5cb54, #9e760d);
			width: 80px;
			height: 30px;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28upx;
		}
	}

	.left {
		text-align: left;
		.tran-type {
			font-size: $font-base;
			color: $font-color-dark;
		}
		
		.tran-time{
			font-size: $font-base;
			color: $font-color-light;
			padding-top:20upx;
		}
	}
	.right {
		text-align: right;
		.point-plus {
			font-size: $font-lg;
			color: #D47169;
		}
		.point-minus {
			font-size: $font-lg;
			color: green
		}
		.balance{
			font-size: $font-base;
			color: $font-color-light;
			padding-top:20upx;
		}
	}
	

	.icon-bianji {
		display: flex;
		align-items: center;
		height: 80upx;
		font-size: 40upx;
		color: $font-color-light;
		padding-left: 30upx;
	}
	.point-history{
		margin-top: 10upx;
	}
</style>
